(function(e,t){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=t(require("video.js"))}else if(typeof define==="function"&&define.amd){define(["videojs"],function(i){return e.Youtube=t(i)})}else{e.Youtube=t(e.videojs)}})(this,function(e){"use strict";if(!e){return}var t=e.browser.IS_IOS||e.browser.IS_ANDROID;var i=e.getTech("Tech");var s=e.extend(i,{constructor:function(e,o){i.call(this,e,o);this.setPoster(e.poster);this.setSrc(this.options_.source,true);setTimeout(function(){this.el_.parentNode.className+=" vjs-youtube";if(t){this.el_.parentNode.className+=" vjs-youtube-mobile"}if(s.isApiReady){this.initYTPlayer()}else{s.apiReadyQueue.push(this)}}.bind(this))},dispose:function(){if(this.ytPlayer){this.ytPlayer.stopVideo();this.ytPlayer.destroy()}else{var e=s.apiReadyQueue.indexOf(this);if(e!==-1){s.apiReadyQueue.splice(e,1)}}this.ytPlayer=null;this.el_.parentNode.className=this.el_.parentNode.className.replace(" vjs-youtube","").replace(" vjs-youtube-mobile","");this.el_.parentNode.removeChild(this.el_);i.prototype.dispose.call(this)},createEl:function(){var e=document.createElement("div");e.setAttribute("id",this.options_.techId);e.setAttribute("style","width:100%;height:100%;top:0;left:0;position:absolute");e.setAttribute("class","vjs-tech");var i=document.createElement("div");i.appendChild(e);if(!t&&!this.options_.ytControls){var s=document.createElement("div");s.setAttribute("class","vjs-iframe-blocker");s.setAttribute("style","position:absolute;top:0;left:0;width:100%;height:100%");s.onclick=function(){this.pause()}.bind(this);i.appendChild(s)}return i},initYTPlayer:function(){var e={controls:0,modestbranding:1,rel:0,showinfo:0,loop:this.options_.loop?1:0};if(typeof this.options_.autohide!=="undefined"){e.autohide=this.options_.autohide}if(typeof this.options_["cc_load_policy"]!=="undefined"){e["cc_load_policy"]=this.options_["cc_load_policy"]}if(typeof this.options_.ytControls!=="undefined"){e.controls=this.options_.ytControls}if(typeof this.options_.disablekb!=="undefined"){e.disablekb=this.options_.disablekb}if(typeof this.options_.end!=="undefined"){e.end=this.options_.end}if(typeof this.options_.color!=="undefined"){e.color=this.options_.color}if(!e.controls){e.fs=0}else if(typeof this.options_.fs!=="undefined"){e.fs=this.options_.fs}if(typeof this.options_.end!=="undefined"){e.end=this.options_.end}if(typeof this.options_.hl!=="undefined"){e.hl=this.options_.hl}else if(typeof this.options_.language!=="undefined"){e.hl=this.options_.language.substr(0,2)}if(typeof this.options_["iv_load_policy"]!=="undefined"){e["iv_load_policy"]=this.options_["iv_load_policy"]}if(typeof this.options_.list!=="undefined"){e.list=this.options_.list}else if(this.url&&typeof this.url.listId!=="undefined"){e.list=this.url.listId}if(typeof this.options_.listType!=="undefined"){e.listType=this.options_.listType}if(typeof this.options_.modestbranding!=="undefined"){e.modestbranding=this.options_.modestbranding}if(typeof this.options_.playlist!=="undefined"){e.playlist=this.options_.playlist}if(typeof this.options_.playsinline!=="undefined"){e.playsinline=this.options_.playsinline}if(typeof this.options_.rel!=="undefined"){e.rel=this.options_.rel}if(typeof this.options_.showinfo!=="undefined"){e.showinfo=this.options_.showinfo}if(typeof this.options_.start!=="undefined"){e.start=this.options_.start}if(typeof this.options_.theme!=="undefined"){e.theme=this.options_.theme}if(typeof this.options_.customVars!=="undefined"){var t=this.options_.customVars;Object.keys(t).forEach(function(i){e[i]=t[i]})}this.activeVideoId=this.url?this.url.videoId:null;this.activeList=e.list;this.ytPlayer=new YT.Player(this.options_.techId,{videoId:this.activeVideoId,playerVars:e,events:{onReady:this.onPlayerReady.bind(this),onPlaybackQualityChange:this.onPlayerPlaybackQualityChange.bind(this),onPlaybackRateChange:this.onPlayerPlaybackRateChange.bind(this),onStateChange:this.onPlayerStateChange.bind(this),onError:this.onPlayerError.bind(this)}})},onPlayerReady:function(){if(this.options_.muted){this.ytPlayer.mute()}var e=this.ytPlayer.getAvailablePlaybackRates();if(e.length>1){this.featuresPlaybackRate=true}this.playerReady_=true;this.triggerReady();if(this.playOnReady){this.play()}else if(this.cueOnReady){this.cueVideoById_(this.url.videoId);this.activeVideoId=this.url.videoId}},onPlayerPlaybackQualityChange:function(){},onPlayerPlaybackRateChange:function(){this.trigger("ratechange")},onPlayerStateChange:function(e){var t=e.data;if(t===this.lastState||this.errorNumber){return}this.lastState=t;switch(t){case-1:this.trigger("loadstart");this.trigger("loadedmetadata");this.trigger("durationchange");this.trigger("ratechange");break;case YT.PlayerState.ENDED:this.trigger("ended");break;case YT.PlayerState.PLAYING:this.trigger("timeupdate");this.trigger("durationchange");this.trigger("playing");this.trigger("play");if(this.isSeeking){this.onSeeked()}break;case YT.PlayerState.PAUSED:this.trigger("canplay");if(this.isSeeking){this.onSeeked()}else{this.trigger("pause")}break;case YT.PlayerState.BUFFERING:this.player_.trigger("timeupdate");this.player_.trigger("waiting");break}},onPlayerError:function(e){this.errorNumber=e.data;this.trigger("pause");this.trigger("error")},error:function(){var e=1e3+this.errorNumber;switch(this.errorNumber){case 5:return{code:e,message:"Error while trying to play the video"};case 2:case 100:return{code:e,message:"Unable to find the video"};case 101:case 150:return{code:e,message:"Playback on other Websites has been disabled by the video owner."}}return{code:e,message:"YouTube unknown error ("+this.errorNumber+")"}},loadVideoById_:function(e){var t={videoId:e};if(this.options_.start){t.startSeconds=this.options_.start}if(this.options_.end){t.endEnd=this.options_.end}this.ytPlayer.loadVideoById(t)},cueVideoById_:function(e){var t={videoId:e};if(this.options_.start){t.startSeconds=this.options_.start}if(this.options_.end){t.endEnd=this.options_.end}this.ytPlayer.cueVideoById(t)},src:function(e){if(e){this.setSrc({src:e})}return this.source},poster:function(){if(t){return null}return this.poster_},setPoster:function(e){this.poster_=e},setSrc:function(e){if(!e||!e.src){return}delete this.errorNumber;this.source=e;this.url=s.parseUrl(e.src);if(!this.options_.poster){if(this.url.videoId){this.poster_="https://img.youtube.com/vi/"+this.url.videoId+"/0.jpg";this.trigger("posterchange");this.checkHighResPoster()}}if(this.options_.autoplay&&!t){if(this.isReady_){this.play()}else{this.playOnReady=true}}else if(this.activeVideoId!==this.url.videoId){if(this.isReady_){this.cueVideoById_(this.url.videoId);this.activeVideoId=this.url.videoId}else{this.cueOnReady=true}}},autoplay:function(){return this.options_.autoplay},setAutoplay:function(e){this.options_.autoplay=e},loop:function(){return this.options_.loop},setLoop:function(e){this.options_.loop=e},play:function(){if(!this.url||!this.url.videoId){return}this.wasPausedBeforeSeek=false;if(this.isReady_){if(this.url.listId){if(this.activeList===this.url.listId){this.ytPlayer.playVideo()}else{this.ytPlayer.loadPlaylist(this.url.listId);this.activeList=this.url.listId}}if(this.activeVideoId===this.url.videoId){this.ytPlayer.playVideo()}else{this.loadVideoById_(this.url.videoId);this.activeVideoId=this.url.videoId}}else{this.trigger("waiting");this.playOnReady=true}},pause:function(){if(this.ytPlayer){this.ytPlayer.pauseVideo()}},paused:function(){return this.ytPlayer?this.lastState!==YT.PlayerState.PLAYING&&this.lastState!==YT.PlayerState.BUFFERING:true},currentTime:function(){return this.ytPlayer?this.ytPlayer.getCurrentTime():0},setCurrentTime:function(e){if(this.lastState===YT.PlayerState.PAUSED){this.timeBeforeSeek=this.currentTime()}if(!this.isSeeking){this.wasPausedBeforeSeek=this.paused()}this.ytPlayer.seekTo(e,true);this.trigger("timeupdate");this.trigger("seeking");this.isSeeking=true;if(this.lastState===YT.PlayerState.PAUSED&&this.timeBeforeSeek!==e){clearInterval(this.checkSeekedInPauseInterval);this.checkSeekedInPauseInterval=setInterval(function(){if(this.lastState!==YT.PlayerState.PAUSED||!this.isSeeking){clearInterval(this.checkSeekedInPauseInterval)}else if(this.currentTime()!==this.timeBeforeSeek){this.trigger("timeupdate");this.onSeeked()}}.bind(this),250)}},seeking:function(){return this.isSeeking},seekable:function(){if(!this.ytPlayer){return e.createTimeRange()}return e.createTimeRange(0,this.ytPlayer.getDuration())},onSeeked:function(){clearInterval(this.checkSeekedInPauseInterval);this.isSeeking=false;if(this.wasPausedBeforeSeek){this.pause()}this.trigger("seeked")},playbackRate:function(){return this.ytPlayer?this.ytPlayer.getPlaybackRate():1},setPlaybackRate:function(e){if(!this.ytPlayer){return}this.ytPlayer.setPlaybackRate(e)},duration:function(){return this.ytPlayer?this.ytPlayer.getDuration():0},currentSrc:function(){return this.source&&this.source.src},ended:function(){return this.ytPlayer?this.lastState===YT.PlayerState.ENDED:false},volume:function(){return this.ytPlayer?this.ytPlayer.getVolume()/100:1},setVolume:function(e){if(!this.ytPlayer){return}this.ytPlayer.setVolume(e*100);this.setTimeout(function(){this.trigger("volumechange")},50)},muted:function(){return this.ytPlayer?this.ytPlayer.isMuted():false},setMuted:function(e){if(!this.ytPlayer){return}else{this.muted(true)}if(e){this.ytPlayer.mute()}else{this.ytPlayer.unMute()}this.setTimeout(function(){this.trigger("volumechange")},50)},buffered:function(){if(!this.ytPlayer||!this.ytPlayer.getVideoLoadedFraction){return e.createTimeRange()}var t=this.ytPlayer.getVideoLoadedFraction()*this.ytPlayer.getDuration();return e.createTimeRange(0,t)},preload:function(){},load:function(){},reset:function(){},supportsFullScreen:function(){return true},checkHighResPoster:function(){var e="https://img.youtube.com/vi/"+this.url.videoId+"/maxresdefault.jpg";try{var t=new Image;t.onload=function(){if("naturalHeight"in t){if(t.naturalHeight<=90||t.naturalWidth<=120){return}}else if(t.height<=90||t.width<=120){return}this.poster_=e;this.trigger("posterchange")}.bind(this);t.onerror=function(){};t.src=e}catch(e){}}});s.isSupported=function(){return true};s.canPlaySource=function(e){return s.canPlayType(e.type)};s.canPlayType=function(e){return e==="video/youtube"};s.parseUrl=function(e){var t={videoId:null};var i=/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;var s=e.match(i);if(s&&s[2].length===11){t.videoId=s[2]}var o=/[?&]list=([^#\&\?]+)/;s=e.match(o);if(s&&s[1]){t.listId=s[1]}return t};function o(){YT.ready(function(){s.isApiReady=true;for(var e=0;e<s.apiReadyQueue.length;++e){s.apiReadyQueue[e].initYTPlayer()}})}function r(e,t){var i=false;var s=document.createElement("script");var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(s,o);s.onload=function(){if(!i){i=true;t()}};s.onreadystatechange=function(){if(!i&&(this.readyState==="complete"||this.readyState==="loaded")){i=true;t()}};s.src=e}function n(){var e=".vjs-youtube .vjs-iframe-blocker { display: none; }"+".vjs-youtube.vjs-user-inactive .vjs-iframe-blocker { display: block; }"+".vjs-youtube .vjs-poster { background-size: cover; }"+".vjs-youtube-mobile .vjs-big-play-button { display: none; }";var t=document.head||document.getElementsByTagName("head")[0];var i=document.createElement("style");i.type="text/css";if(i.styleSheet){i.styleSheet.cssText=e}else{i.appendChild(document.createTextNode(e))}t.appendChild(i)}s.apiReadyQueue=[];r("https://www.youtube.com/iframe_api",o);n();if(typeof e.registerTech!=="undefined"){e.registerTech("Youtube",s)}else{e.registerComponent("Youtube",s)}});